package cn.lin.factory.flyweight;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author liufl E-mail:Huberier@allpyra.com
 * @version 创建时间：2017年8月22日 下午6:07:49
 * 类说明
 */
public class FlyweightMode {

	private static ConcurrentHashMap<String, FlyweightModeVO> allFlyweight = new ConcurrentHashMap<String, FlyweightModeVO>();
	
	public  static FlyweightModeVO getFlyweight(String name) {
		if(allFlyweight.get(name)==null){
			synchronized (allFlyweight) {
				if(allFlyweight.get(name)==null){
					FlyweightModeVO mode = new FlyweightModeVO(name);
					allFlyweight.put(name, mode);
				}
			}
		}
		return allFlyweight.get(name);
	}
	
	public static void main(String[] args) {
		String name = "user";
		for (int i = 0; i < 3; i++) {
			FlyweightModeVO mode = FlyweightMode.getFlyweight(name);
			System.out.println(String.format("mode:{%s}",mode.hashCode()));
		}
	}
}

